
#include "WinTalk.h"

WinTalk::WinTalk()
{
	QLabel *image = new QLabel(this);
	image->setPixmap(QPixmap(IMAGE_BG_TALK));
	/*
	QLabel *image5 = new QLabel(this);
	image5->setPixmap(QPixmap("./Images/twitter_"));
	*/

	_timer = new QTimer(this);

	// Menu gauche
	_btn1 = new QPushButton(this);
	_btn1->setStyleSheet("background-image:url(./Images/twitter_ico1.png); border:0;");
	_btn1->setFixedSize(50, 50);
	_btn1->move(10, 60);
	QObject::connect(_btn1, SIGNAL(clicked()), this, SLOT(view1()));

	_btn2 = new QPushButton(this);
	_btn2->setStyleSheet("background-image:url(./Images/twitter_ico2.png); border:0;");
	_btn2->setFixedSize(48, 48);
	_btn2->move(10, 150);
	QObject::connect(_btn2, SIGNAL(clicked()), this, SLOT(view2()));

	_btn3 = new QPushButton(this);
	_btn3->setStyleSheet("background-image:url(./Images/twitter_ico3.png); border:0;");
	_btn3->setFixedSize(46, 48);
	_btn3->move(10, 240);

	_btn4 = new QPushButton(this);
	_btn4->setStyleSheet("background-image:url(./Images/twitter_ico4.png); border:0;");
	_btn4->setFixedSize(48, 48);
	_btn4->move(10, 320);

	// Main Frame
	_mainFrame = new QFrame(this);
	_mainFrame->setFixedSize(400, 600);
	_mainFrame->move(200, 0);
	_mainFrame->setStyleSheet("background-color:white;");

	// See Frame
	_seeFrame = new QFrame(_mainFrame);
	_seeFrame->setFixedSize(400, 500);
	_seeFrame->move(0, 0);
	_seeFrame->setStyleSheet("background-color:yellow;");

	// Talk Frame
	_talkFrame = new QFrame(_mainFrame);
	_talkFrame->setFixedSize(400, 100);
	_talkFrame->move(0, 500);
	_talkFrame->setStyleSheet("background-color:red;");

	// Txt 1
	// _txt1 = new QLabel("What are you doing ?", _talkFrame);

	// Text Edit
	_whatAreYouDoing = new QTextEdit(_talkFrame);
	_whatAreYouDoing->setFixedSize(300, 50);
	_whatAreYouDoing->move(75, 10);
	QObject::connect(_whatAreYouDoing, SIGNAL(textChanged()), this, SLOT(manageTxtEdit()));

	// Image
	_avatar = new QLabel(_talkFrame);
	_avatar->move(10, 40);
	_avatar->setPixmap(QPixmap(IMAGE_AVATAR_TALK));
	_avatar->setStyleSheet("border:1;");

	// Nombre de caracteres a mettre restants
	_txtChar = new QLabel(_talkFrame);
	_txtChar->move(75, 65);
	_txtChar->setFixedSize(40, 10);

	// Btn mise a jour
	_btnUpdate = new QPushButton(_talkFrame);
	_btnUpdate->move(350, 65);
	_btnUpdate->setFixedSize(24, 24);
	_btnUpdate->setStyleSheet("background-image:url(./Images/twitter_update.png); border:0;");
	QObject::connect(_btnUpdate, SIGNAL(clicked()), this, SLOT(manageTxtEdit()));
}

void	WinTalk::manageTxtEdit()
{
	int nbChar = 140 - _whatAreYouDoing->toPlainText().size();

	QString	text_integer;
	text_integer.setNum(nbChar);
	_txtChar->setText(text_integer);
}

void	WinTalk::view1()
{
	connect(_timer, SIGNAL(timeout()), this, SLOT(hideTFrame()));
	_timer->start(5);
}

void	WinTalk::view2()
{
	connect(_timer, SIGNAL(timeout()), this, SLOT(showTFrame()));
	_timer->start(5);
}

void	WinTalk::showTFrame()
{
	if (!_talkFrame->isVisible())
		_talkFrame->setVisible(true);
	if (_talkFrame->y() > 500)
	{
		_seeFrame->setFixedSize(_seeFrame->size().width(), _seeFrame->size().height() - 1); 
		_talkFrame->move(_talkFrame->x(), _talkFrame->y() - 1);
	}
	else
	{
		_seeFrame->setFixedSize(_seeFrame->size().width(), 500);
		_talkFrame->move(_talkFrame->x(), 500);
		_timer->stop();
	}
}

void	WinTalk::hideTFrame()
{
	if (_talkFrame->y() < 600)
	{
		_seeFrame->setFixedSize(_seeFrame->size().width(), _seeFrame->size().height() + 1); 
		_talkFrame->move(_talkFrame->x(), _talkFrame->y() + 1);
	}
	else
	{
		_talkFrame->setVisible(false);
		_timer->stop();
	}
}

void	WinTalk::sendMsg()
{
	;
}

WinTalk::~WinTalk()
{

}